package controller.res;

import model.MResourceAuthority;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import common.interf.IErrorHandle;

import service.interf.IResource;

@Controller
@RequestMapping("/res")
public class ResourceAuthorityController {

	@Autowired
	private IResource res;
	@Autowired
	private IErrorHandle errorHandle;
	
	@RequestMapping("/update_resauth.htm")
	@ResponseBody
	public String updateResourceAuthority(MResourceAuthority model) {
		String s ="";
		try {
//			String resAuth = "1,1,2";
			s = res.updateResourceAuthority(model.getResourceAuthority());
		} catch (Exception e) {
			errorHandle.handleErr(e);
		}
		return s;
	}//debug pass
	
	@RequestMapping("/update_authres.htm")
	@ResponseBody
	public String updateAuthorityResource(MResourceAuthority model) {
		String s ="";
		try {
			s = res.updateAuthorityResources(model.getAuthorityId(), model.getAuthorityResource());
		} catch (Exception e) {
			errorHandle.handleErr(e);
		}
		return s;
	}
	
	@RequestMapping("/find_resauth.htm")
	@ResponseBody
	public String findResourceAuthoritites(MResourceAuthority model) {
		String s ="";
		try {
			s = res.getResourceAuthorities(model.getResourceId());
		} catch (Exception e) {
			errorHandle.handleErr(e);
		}
		return s;
	}//PASS
	
	@RequestMapping("/find_authres.htm")
	@ResponseBody
	public String findAuthorityResource(MResourceAuthority model) {
		String s ="";
		try {
			s = res.getResourceByAuth(model.getAuthorityId());
		} catch (Exception e) {
			errorHandle.handleErr(e);
		}
		return s;
	}//debug pass
	
}
